package com.woniuxy.project.campus.account.controller;


import cn.hutool.core.bean.BeanUtil;
import com.woniuxy.project.campus.account.dto.GetAllAuthorityName;
import com.woniuxy.project.campus.account.model.form.UpdateUserAuthorityNameForm;
import com.woniuxy.project.campus.account.param.UpdateUserAuthorityNameParam;
import com.woniuxy.project.campus.account.service.RoleService;
import com.woniuxy.project.campus.util.Result;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 吴彦祖
 * @since 2025年02月17日
 */
@RestController
@RequestMapping("/role")
public class RoleController {

    @Resource
    private RoleService roleService;

    @ApiOperation(value = "管理员查看所有的权限名", notes = "管理员查看所有的权限名")
    @GetMapping("/getAllAuthorityName")
    public Result getAllAuthorityName(@RequestHeader("token") String token) {
        List<GetAllAuthorityName> authorityNameList = roleService.getAllAuthorityName(token);
        return Result.success(authorityNameList);
    }

    //管理员修改用户权限名
    @ApiOperation(value = "管理员修改用户角色名", notes = "传入用户id，修改用户权限名")
    @PostMapping("/updateUserAuthorityName")
    public Result updateUserAuthorityName(@RequestHeader("token") String token,@RequestBody UpdateUserAuthorityNameForm form) throws Exception {
        UpdateUserAuthorityNameParam bean = BeanUtil.toBean(form, UpdateUserAuthorityNameParam.class);
        bean.setToken(token);
        roleService.updateUserAuthorityName(bean);
        return Result.success("修改成功");
    }
}

